Technical Q&A QA1153
Deadlocks When Switching Between Windows


Q: My Java application occasionally locks up when switching between two JFrames with my mouse. What's wrong?

A: There is a known issue in the current Java 1.3.1 implementation that can cause a hang when clicking between two windows. The problem has been seen when activating a JFrame that has a tooltip registered, as well as switching to a JFrame and immediately opening a JMenu.

The issue can be worked around rather simply by doing the following:

  1. Add a WindowListener to the frames exhibiting the problem.
  2. Implement the listener's windowActivated() method to call toFront() on the activated frame to ensure that it actually has focus when it is selected, before any other actions are performed.
You should be able to use a single WindowListener for all of your problematic frames to keep things simple. Please note that this is an uncommon problem and should only be applied to areas that demonstrate the problem, not as a general practice.


[Jul 12 2002]


Developer Documentation | Technical Notes | Development Kits | Sample Code